package cn.tq365.util.mybatis;

import java.io.IOException;
import java.io.Reader;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

/**
 * 自定义SqlSessionFactory工具类
 * 
 * @author lili
 * 
 */
public class SqlSessionFactoryUtil {
	private String configLocation;
	private SqlSessionFactory sqlSessionFactory = null;

	public SqlSessionFactory getSqlSessionFactory() throws IOException {
		if (sqlSessionFactory == null) {
			Reader reader = null;
			try {
				reader = Resources.getResourceAsReader(configLocation);
			} catch (IOException e) {
				e.printStackTrace();
			}
			SqlSessionFactoryBuilder builder = new SqlSessionFactoryBuilder();
			sqlSessionFactory = builder.build(reader);
		}
		return sqlSessionFactory;
	}

	public String getConfigLocation() {
		return configLocation;
	}

	public void setConfigLocation(String configLocation) {
		this.configLocation = configLocation;

	}

}
